package com.xjc.business.controller.sysadmin;

import com.xjc.business.entity.po.sysadmin.SysAdminLoginPo;
import com.xjc.business.entity.vo.sysadmin.SysAdminLoginVo;
import com.xjc.business.service.SysAdminsService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 徐锦程
 * 时间:2025-01-25 17:36
 */
@RestController
@RequestMapping("/sys_admin/user")
public class SysUserController {

    @Autowired
    private SysAdminsService sysAdminsService;

    /**
     * 登录
     * @param sysAdminLoginPo 登录参数
     * @return 登录成功返回token，失败返回错误信息
     */
    @PostMapping("/login")
    public Result<SysAdminLoginVo> doLogin(@RequestBody(required = false) SysAdminLoginPo sysAdminLoginPo){
        if(sysAdminLoginPo == null || sysAdminLoginPo.getUsername() == null || sysAdminLoginPo.getPassword() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return sysAdminsService.doLogin(sysAdminLoginPo);
    }
}